package com.fxnotes.page.node;

import com.fxnotes.common.ui.CustomNode;
import com.fxnotes.domain.model.Book;
import com.fxnotes.domain.model.Chapter;
import com.fxnotes.domain.model.Page;
import com.fxnotes.page.presenter.PageViewPresenter;
import com.google.inject.Inject;
import javafx.scene.Parent;
import javafx.scene.control.Label;
import javafx.scene.control.TextArea;
import javafx.scene.text.Font;
import org.tbee.javafx.scene.layout.MigPane;

public class PageViewNode implements CustomNode<Parent> {

    private Label bookLabel;
    private Label chapterLabel;
    private Label pageDescriptionLabel;
    private TextArea pageDescription;
    private Label pageDetailsLabel;
    private TextArea pageDetails;
    private MigPane pane;
    private PageViewPresenter presenter;

    public PageViewNode() {
        initUI();
        initHandlers();
    }

    // API
    @Inject
    public void setPresenter(PageViewPresenter presenter) {
        this.presenter = presenter;
    }

    @Override
    public Parent getNode() {
        return pane;
    }

    private void initUI() {
        pane = new MigPane("fillx", "[grow, fill]");

        bookLabel = new Label();
        bookLabel.setFont(new Font(18));

        chapterLabel = new Label();
        chapterLabel.setFont(new Font(15));

        pageDescriptionLabel = new Label("Description:");
        pageDescriptionLabel.setFont(new Font(14));

        pageDescription = new TextArea();
        pageDescription.setEditable(false);
        
        pageDetailsLabel = new Label("Details:");
        pageDetailsLabel.setFont(new Font(14));
        
        pageDetails = new TextArea();
        pageDetails.setEditable(false);        

        pane.add(bookLabel, "wrap, newline 10px");
        pane.add(chapterLabel, "wrap, newline 10px");
        pane.add(pageDescriptionLabel, "wrap, newline 5px");
        pane.add(pageDescription, "wrap");
        pane.add(pageDetailsLabel, "wrap, newline 5px");
        pane.add(pageDetails, "growy");
    }

    public void loadPage(Book book, Chapter chapter, Page page) {
        bookLabel.setText(book.getName());
        chapterLabel.setText(chapter.getName());
        pageDescription.setText(page.getName());
    }
    
    private void initHandlers() {
    }    
}
